import Mock from "mockjs";

const { data } = Mock.mock({
  "data|20": [
    {
      "id|+1": 1,
      stuats: "@ctitle(3)",
      adress: "@county(true)",
    },
  ],
});

class NewData {
  getData() {
    return new Promise((resolve) => {
      resolve({
        status: 0,
        list: data,
      });
    });
  }
}

export const news = new NewData();
const { listdata } = Mock.mock({
    "listdata|100": [
      {
        status: 0,
        "id|+1": 1,
        'a|1-10000000': 10000000,
        "goodsSale|30-500": 30,
        stuats: "@ctitle(3)",
        timer:'@date()',
        adress: "@county(true)",
        miao:"@natural(60, 100)",
        "number|1-10": 1
      },
    ],
  });

  class ListData {
    getlistData(params) {
      const { pageSize = 10, currentPage = 1,} = params;
      const result = listdata
      .slice((currentPage - 1) * pageSize, currentPage * pageSize);
      return new Promise((resolve) => {
        resolve({
          status: 0,
          list: result,
          count: listdata.length,
        });
      });
    }
    adddata(a,b){
      if(listdata){
        listdata.unshift({
          stuats : a,
          adress : b,
          time:new Date()
        })
        return new Promise((resolve) => {
          resolve({
            status: 0,
            message : "添加成功"
          });
        });
      }
    }
    remove(params){
        if(confirm("确定删除吗")){
        if(listdata){
          for(let i = 0;i<=params.ids.length-1;i++){
              listdata.map((el,index)=>{
                if(el.id === params.ids[i]){
                  listdata.splice(index,1)
                }
              })
          }
        }
      }
    }
  }

export const list = new ListData()
